package com.concerneyes.pay;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.concerneyes.R;

import common.AbsActivity;

/**
 * Created by Administrator on 2017/8/9 0009.
 */

public class FaPiaoActivity extends AbsActivity implements View.OnClickListener {
    private static final int NO_FAPIAO = 0;
    private static final int PAPER_FAPIAO = 1;
    private static final int DIANZI_FAPIAO = 2;
    private ImageView mIvNoFapiao;
    private LinearLayout mLlNoFapiao;
    private ImageView mIvFapiaoPaper;
    private LinearLayout mLlFapiaoPaper;
    private ImageView mIvFapiaoDianzi;
    private LinearLayout mLlFapiaoDianzi;
    private ImageView mIvGeren;
    private LinearLayout mLlGeren;
    private ImageView mIvDanwei;
    private LinearLayout mLlDanwei;
    private TextView mFapiao;
    private EditText mEtFapiaoTop;
    private RelativeLayout mRlFaPiao;
    private TextView mAddNum;
    private EditText mEtAddNum;
    private RelativeLayout mRlAddNum;
    private TextView mEms;
    private EditText mEtEms;
    private RelativeLayout mRlEms;
    private LinearLayout mLlFapiaoDetail;
    private LinearLayout mLlDetail;
    private LinearLayout mLlFapiaoTitle;
    private Drawable select;
    private Drawable unselect;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_fapiao);
        initView();
        setTitle(R.string.fapiao);
        getRightText().setVisibility(View.VISIBLE);
        getRightText().setText(R.string.yes);
    }

    @Override
    public void onRightTextAction(View v) {
        super.onRightTextAction(v);

    }

    private void initView() {
        select = getResources().getDrawable(R.drawable.btn_selected);
        unselect = getResources().getDrawable(R.drawable.btn_unselected);

        mIvNoFapiao = (ImageView) findViewById(R.id.iv_no_fapiao);
        mLlNoFapiao = (LinearLayout) findViewById(R.id.ll_no_fapiao);
        mLlNoFapiao.setOnClickListener(this);
        mIvFapiaoPaper = (ImageView) findViewById(R.id.iv_fapiao_paper);
        mLlFapiaoPaper = (LinearLayout) findViewById(R.id.ll_fapiao_paper);
        mLlFapiaoPaper.setOnClickListener(this);
        mIvFapiaoDianzi = (ImageView) findViewById(R.id.iv_fapiao_dianzi);
        mLlFapiaoDianzi = (LinearLayout) findViewById(R.id.ll_fapiao_dianzi);
        mLlFapiaoDianzi.setOnClickListener(this);
        mIvGeren = (ImageView) findViewById(R.id.iv_geren);
        mLlGeren = (LinearLayout) findViewById(R.id.ll_geren);
        mLlGeren.setOnClickListener(this);
        mIvDanwei = (ImageView) findViewById(R.id.iv_danwei);
        mLlDanwei = (LinearLayout) findViewById(R.id.ll_danwei);
        mLlDanwei.setOnClickListener(this);
        mFapiao = (TextView) findViewById(R.id.fapiao);
        mEtFapiaoTop = (EditText) findViewById(R.id.et_fapiao_top);
        mRlFaPiao = (RelativeLayout) findViewById(R.id.rl_fa_piao);
        mAddNum = (TextView) findViewById(R.id.add_num);
        mEtAddNum = (EditText) findViewById(R.id.et_add_num);
        mRlAddNum = (RelativeLayout) findViewById(R.id.rl_add_num);
        mEms = (TextView) findViewById(R.id.ems);
        mEtEms = (EditText) findViewById(R.id.et_ems);
        mRlEms = (RelativeLayout) findViewById(R.id.rl_ems);
        mLlFapiaoDetail = (LinearLayout) findViewById(R.id.ll_fapiao_detail);
        mLlDetail = (LinearLayout) findViewById(R.id.ll_detail);
        mLlFapiaoTitle = (LinearLayout) findViewById(R.id.ll_fapiao_title);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.ll_no_fapiao:
                setFapiaoType(NO_FAPIAO);
                break;
            case R.id.ll_fapiao_paper:
                setFapiaoType(PAPER_FAPIAO);
                break;
            case R.id.ll_fapiao_dianzi:
                setFapiaoType(DIANZI_FAPIAO);
                break;
            case R.id.ll_geren:
                isMain(true);

                break;
            case R.id.ll_danwei:
                isMain(false);

                break;
        }
    }

    private void isMain(boolean isMain) {
        if (isMain) {
            mIvGeren.setImageDrawable(select);
            mIvDanwei.setImageDrawable(unselect);

            mLlFapiaoTitle.setVisibility(View.VISIBLE);
            mLlFapiaoDetail.setVisibility(View.GONE);
            mLlDetail.setVisibility(View.VISIBLE);
        } else {
            mIvGeren.setImageDrawable(unselect);
            mIvDanwei.setImageDrawable(select);

            mLlFapiaoTitle.setVisibility(View.VISIBLE);
            mLlFapiaoDetail.setVisibility(View.VISIBLE);
            mLlDetail.setVisibility(View.VISIBLE);
        }
    }

    public void setFapiaoType(int fapiaoType) {
        if (fapiaoType == NO_FAPIAO) {
            mIvNoFapiao.setImageDrawable(select);
            mIvFapiaoPaper.setImageDrawable(unselect);
            mIvFapiaoDianzi.setImageDrawable(unselect);
            mLlFapiaoTitle.setVisibility(View.GONE);
            mLlFapiaoDetail.setVisibility(View.GONE);
            mLlDetail.setVisibility(View.GONE);
        } else if (fapiaoType == PAPER_FAPIAO) {
            mIvNoFapiao.setImageDrawable(unselect);
            mIvFapiaoPaper.setImageDrawable(select);
            mIvFapiaoDianzi.setImageDrawable(unselect);
            isMain(true);
            mLlFapiaoTitle.setVisibility(View.VISIBLE);
            mLlDetail.setVisibility(View.VISIBLE);
            mRlEms.setVisibility(View.GONE);
        } else {
            mIvNoFapiao.setImageDrawable(unselect);
            mIvFapiaoPaper.setImageDrawable(unselect);
            mIvFapiaoDianzi.setImageDrawable(select);
            isMain(true);
            mLlFapiaoTitle.setVisibility(View.VISIBLE);
            mLlDetail.setVisibility(View.VISIBLE);
            mRlEms.setVisibility(View.VISIBLE);
        }
    }
}
